package com.qiyi.player.wonder.plugins.setting.view.parts
{
   import flash.display.Sprite;
   import com.qiyi.player.base.pub.EnumItem;
   import flash.text.TextField;
   import com.qiyi.player.wonder.common.ui.FastCreator;
   import flash.events.MouseEvent;
   import com.qiyi.player.wonder.common.utils.ChineseNameOfLangAudioDef;
   import flash.text.TextFieldAutoSize;
   
   public class DefinitionItem extends Sprite
   {
      
      public function DefinitionItem(param1:EnumItem) {
         super();
         this._data = param1;
         this._textField = FastCreator.createLabel("",10066329,12,TextFieldAutoSize.CENTER);
         this._textField.defaultTextFormat = FastCreator.createTextFormat(FONT_TYPE);
         this._textField.x = 15;
         this._textField.y = 3;
         this._textField.width = 26;
         this._textField.htmlText = this.getTextByEnumItem();
         this._textField.mouseEnabled = this._textField.selectable = false;
         addChild(this._textField);
         addEventListener(MouseEvent.ROLL_OVER,this.onItemRollOver);
         addEventListener(MouseEvent.ROLL_OUT,this.onItemRollOut);
      }
      
      private static const FONT_TYPE:String = "微软雅黑";
      
      private var _data:EnumItem;
      
      private var _textField:TextField;
      
      private var _isSelected:Boolean = false;
      
      private var _isVid:Boolean = false;
      
      public function get isVid() : Boolean {
         return this._isVid;
      }
      
      public function set isVid(param1:Boolean) : void {
         this._isVid = param1;
         if(param1)
         {
            this._textField.defaultTextFormat = FastCreator.createTextFormat(FONT_TYPE,12,10079283);
            this._textField.htmlText = this.getTextByEnumItem();
         }
         else
         {
            this._textField.defaultTextFormat = FastCreator.createTextFormat(FONT_TYPE,12,10066329);
            this._textField.htmlText = this.getTextByEnumItem();
         }
      }
      
      public function get isSelected() : Boolean {
         return this._isSelected;
      }
      
      public function set isSelected(param1:Boolean) : void {
         this._isSelected = param1;
         if(param1)
         {
            this._textField.defaultTextFormat = FastCreator.createTextFormat(FONT_TYPE,12,16777215);
            this._textField.htmlText = this.getTextByEnumItem();
            if(this.isVid)
            {
               this._textField.defaultTextFormat = FastCreator.createTextFormat(FONT_TYPE,12,10079283);
               this._textField.htmlText = this.getTextByEnumItem();
            }
            graphics.clear();
            graphics.beginFill(10079283,0.6);
            graphics.drawRect(0,0,60,26);
            graphics.endFill();
         }
         else
         {
            this._textField.defaultTextFormat = FastCreator.createTextFormat(FONT_TYPE,12,10066329);
            this._textField.htmlText = this.getTextByEnumItem();
            if(this.isVid)
            {
               this._textField.defaultTextFormat = FastCreator.createTextFormat(FONT_TYPE,12,10079283);
               this._textField.htmlText = this.getTextByEnumItem();
            }
            graphics.clear();
         }
      }
      
      public function get data() : EnumItem {
         return this._data;
      }
      
      private function onItemRollOver(param1:MouseEvent) : void {
         if(!this._isSelected)
         {
            graphics.clear();
            graphics.beginFill(10079283,0.2);
            graphics.drawRect(0,0,60,26);
            graphics.endFill();
         }
      }
      
      private function onItemRollOut(param1:MouseEvent) : void {
         if(!this._isSelected)
         {
            graphics.clear();
         }
      }
      
      private function getTextByEnumItem() : String {
         var _loc1_:String = ChineseNameOfLangAudioDef.getDefinitionName(this._data);
         return _loc1_ == ""?"自动":_loc1_;
      }
      
      public function destroy() : void {
         this.graphics.clear();
         removeEventListener(MouseEvent.ROLL_OVER,this.onItemRollOver);
         removeEventListener(MouseEvent.ROLL_OUT,this.onItemRollOut);
         removeChild(this._textField);
         this._textField = null;
      }
   }
}
